



public class IfStmt extends Statement {

	Expression expression;
	Statement statement1;
	Statement statemen2;

	public IfStmt(Expression expression, Statement statement1,
			Statement statemen2) {
		super();
		this.expression = expression;
		this.statement1 = statement1;
		this.statemen2 = statemen2;
	}

	public void check() throws SemanticException {
		expression.check();
		statement1.check();
		if (statemen2 != null)
			statemen2.check();
		if (expression.checkType() != Type.BL)
			throw new SemanticException(
					"If statement must have an expression of type boolean");
	}

	public boolean hasReturnStatement() {
		if (statemen2 == null)
			return false;
		return statement1.hasReturnStatement()
				&& statemen2.hasReturnStatement();
	}

	public IfStmt(Expression expression, Statement statement1) {
		super();
		this.expression = expression;
		this.statement1 = statement1;
	}

	public void setElseStatement(Statement s) {
		statemen2 = s;
	}

	public String toString() {
		String ret = "IfStmt\n";
		String s = "" + expression.toString() + "then " + statement1.toString();
		if (statemen2 != null)
			s += "else " + statemen2;
		for (String st : s.split("\n"))
			ret += "| " + st + "\n";
		return ret;
	}
}
